package com.aca.market.controller;


import com.aca.market.entity.Storage;
import com.aca.market.service.IStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 仓储表 前端控制器
 * </p>
 *
 * @author aca
 * @since 2020-11-13
 */
@Controller
@RequestMapping("/storage")
public class StorageController {

    @Autowired
    IStorageService storageService;

    @GetMapping("/detail/")
    public Storage getStorage(@RequestParam Long itemId,Model model){
        Storage storage = storageService.getById(itemId);
        model.addAttribute("storage"+itemId.toString(),storage);
        return storage;
    }

    @GetMapping("/list")
    public String listStorage(Model model){
        model.addAttribute("storage",storageService.list());
        return "storage-list";
    }

    @PostMapping("/update")
    @ResponseBody
    public Boolean updateStorage(Storage storage){
        Storage tmp = storage;
        tmp.setUpdateTime(LocalDateTime.now());
        return storageService.updateById(tmp);
    }



    @PostMapping("/del/{itemId}")
    @ResponseBody
    public boolean delStorage(@PathVariable Long itemId){
        return storageService.removeById(itemId);
    }

    //删多个
    @PostMapping("/delete/{itemIdList}")
    @ResponseBody
    public boolean delStorageList(@PathVariable List<Long> itemIdList){
        return storageService.removeByIds(itemIdList);
    }


}


